package Stack;

/**
 * @author yyq
 * @create 2021-10-08 16:14
 */
public class ArrayStack<T> {
    private int Max_Size;
    //top始终指向数据上方
    private int top;
    private Object[] stack;

    public ArrayStack(int max_Size) {
        top=0;
        Max_Size = max_Size;
        stack=new Object[max_Size];

    }

    public void push(T val){
        //检查是否超过Maxsize
        if(top<Max_Size){
            stack[top]=val;
            top++;
        }
        else{
            System.out.println("超过最大容量，注入失败");
        }
    }

    public Boolean isEmpty(){
        if(top==0) return true;
        else return false;
    }

    public  T pop() {
        if(top==0){
            System.out.println("没得数据了，老表");
            return null;
        }
        if(top!=0){
            top--;
            return (T) stack[top];
        }
        return null;
    }

    public int getTop(){
        return top;
    }

}
